#!/bin/bash

source /home/shell/util.sh

apt update
apt-get install -y curl openssh-server ca-certificates tzdata perl postfix
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash

#sed -i "s/packages.gitlab.com/mirrors.tuna.tsinghua.edu.cn/g" /etc/apt/sources.list.d/gitlab_gitlab-ce.list
sed -i "s/hirsute/focal/g" /etc/apt/sources.list.d/gitlab_gitlab-ce.list

apt update
apt install -y gitlab-ce

sed -ri "s@external_url 'http://gitlab.example.com'@external_url 'http://"$host_addr"'@g" /etc/gitlab/gitlab.rb
sed -ri "s/# gitlab_rails\['time_zone'\] = 'UTC'/gitlab_rails\['time_zone'\] = 'Asia\/Shanghai'/g" /etc/gitlab/gitlab.rb
sed -ri "s/# gitlab_rails\['gitlab_shell_ssh_port'\] = 22/gitlab_rails\['gitlab_shell_ssh_port'\] = 22/g" /etc/gitlab/gitlab.rb

gitlab-ctl reconfigure && gitlab-ctl restart
/opt/gitlab/bin/gitlab-rake cache:clear

firewall-addservice http

printInfo "=========================gitlab========================="
printInfo "访问地址：http://$host_addr/"
printInfo "配置：/etc/gitlab/gitlab.rb"
printInfo "初始账号：root"
printInfo "初始密码：`cat /etc/gitlab/initial_root_password|grep "Password:"|perl -pe "s/^Password:\s+(.*)/\1/g"`"
printInfo "=========================gitlab========================="